#include "register.h"

static int registers[2][6];
registers[0] = {"eax", "ebx", "ecx", "edx", "esi", "edi"};
registers[1] = {0,0,0,0,0,0};

int register_alloc()
{
  //do not allocate %eax
  int i;
  for (i=1; i<6; i++)
  {
    if (registers[1][i] == 0)
    {
      registers[1][i] = 1;
      return i;
    }
  }
  fprintf(stderr, "Tried to allocate. Out of registers. \n");
  exit(1);
}

void register_free(int r)
{
  registers[1][r] = 0;
}

const char * register_name(int r)
{
  return registers[0][r];
}
